package objects;

import java.util.ArrayList;

import parser.Entry;
import utils.Damage_skill_data;
import utils.Ids_actions;

public class Skill_durations {

	protected ArrayList<Skill_duration> skills_durations;
	protected ArrayList<Entry> entries;
	protected Long target;
	protected Long Skill_id;
	protected Damage_skill_data datas;

	
	public Skill_durations(Long target, Long skill_id){
		this.target = target;
		this.Skill_id = skill_id;
		this.entries = new ArrayList<Entry>();
	}
	
	public void add(Entry one_entry){
		this.entries.add(one_entry);
	}
	
	public void print_entries(){
		for(int i = 0; i<this.entries.size();i++){
			if(this.entries.get(i).getMyskill().getSkillevent_action_id().equals(Skill_id)){
				System.out.println(this.entries.get(i).getLine());
			}
		}
	}
	
	public void populate_skill_duration(){
		boolean beginned = false;
		this.skills_durations = new ArrayList<Skill_duration>();
		Skill_duration duration = new Skill_duration(this.target); 
		for(int i=0;i<this.entries.size();i++){
			if(!beginned){
				if((this.entries.get(i).getMyskill().getSkillevent_id().equals(Ids_actions.applicationeffet))
						&&(this.entries.get(i).getMyskill().getSkillevent_action_id().equals(this.Skill_id))){
					beginned = true;
					duration = new Skill_duration(this.target);
					duration.setStart(this.entries.get(i).getTime());
					duration.incrementStack();
				}
			}else{
				if((this.entries.get(i).getMyskill().getSkillevent_id().equals(Ids_actions.applicationeffet))
						&&(this.entries.get(i).getMyskill().getSkillevent_action_id().equals(this.Skill_id))){
					duration.incrementStack();
				}else if(this.entries.get(i).getMyskill().getSkillevent_id().equals(Ids_actions.retraiteffet)){
					duration.decrementStack();
					if(duration.stack==0){
						duration.setStop(this.entries.get(i).getTime());
						duration.setcalculation();
						duration.calculate_duration();
						this.skills_durations.add(duration);
						beginned = false;
					}	
				}else if(!this.entries.get(i).getMyskill().getSkillevent_id().equals(Ids_actions.evenement)){
					if(this.entries.get(i).getMyskill().numeric_value!=null){
						duration.add_entry(this.entries.get(i));
					}
				}
			}
		}
	}
	public void calculate_information(){
		this.datas = new Damage_skill_data();
		
		for(int i = 0;i<this.skills_durations.size();i++){
			this.datas.incrementNb_crit(this.skills_durations.get(i).getDatas().getNb_crit());
			this.datas.incrementSum_crit(this.skills_durations.get(i).getDatas().getSum_crit());
			this.datas.setCrit_max(this.skills_durations.get(i).getDatas().getCrit_max());
			this.datas.setCrit_min(this.skills_durations.get(i).getDatas().getCrit_max());
			this.datas.incrmentNb_normal(this.skills_durations.get(i).getDatas().getNb_normal());
			this.datas.incrementSum_normal(this.skills_durations.get(i).getDatas().getSum_normal());
			this.datas.setNormal_max(this.skills_durations.get(i).getDatas().getNormal_max());
			this.datas.setNormal_min(this.skills_durations.get(i).getDatas().getNormal_min());
		}
		this.datas.calculateMoyenne();
		this.datas.calculateMoyenne_crit();
		this.datas.calculateMoyenne_normal();
	}

	public Long getTarget() {
		return target;
	}

	public Long getSkill_id() {
		return Skill_id;
	}

	public Damage_skill_data getDatas() {
		return datas;
	}
	
	
}
